#!/bin/bash
#version:v23.05.14
# cd ~ &&  wget -O  init.sh  https://gitee.com/thinkyoung/ENV/raw/master/Arch/pool/main/i/init/init.sh  &&  sudo bash init.sh
#PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
#export PATH
#LANG=en_US.UTF-8






# 安装自定义alias
Alias(){
cd ~

echo '
# include .bash_aliases if it exists
if [ -f $HOME/.bash_aliases ]; then
    . $HOME/.bash_aliases
fi
' | tee -a ~/.bashrc   
cd ~ && sudo wget -O  .bash_aliases   https://gitee.com/thinkyoung/ENV/raw/master/Arch/pool/main/a/alias/.bash_aliases  &&  source  ~/.bashrc && source  ~/.bash_aliases


echo -e "\033[33m $FUNCNAME \033[0m" 
alias
pause "$FUNCNAME OK！"
}





# 添加自定义源
Source(){

    
# 添加自定义源：国内源
sudo pacman-mirrors -i -c China -m rank

sudo pacman-mirrors -g

echo '
[archlinuxcn]
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinuxcn/$arch
Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch
' | sudo tee -a    /etc/pacman.conf

sudo pacman -Syyu 
sudo pacman -S archlinuxcn-keyring


echo -e "\033[33m $FUNCNAME \033[0m"
cat /etc/pacman.conf
pause "$FUNCNAME OK！"
}

# zh fonts 安装
Fonts(){
    
sudo pacman -S adobe-source-han-sans-cn-fonts
sudo pacman -S adobe-source-han-serif-cn-fonts
sudo pacman -S noto-fonts-sc
sudo pacman -S noto-fonts-cjk

sudo pacman -S wqy-microhei
sudo pacman -S wqy-zenhei
sudo pacman -S wqy-bitmapfont
sudo pacman -S ttf-arphic-ukai
sudo pacman -S ttf-arphic-uming
sudo pacman -S opendesktop-fonts
sudo pacman -S ttf-hannom




echo -e "\033[33m $FUNCNAME \033[0m" 
pause "$FUNCNAME OK！"
}


# pkg tools 安装
Aur(){
    
sudo pacman -S yay fish screenfetch zsh oh-my-zsh trash-cli base-devel




echo -e "\033[33m $FUNCNAME \033[0m" 
pause "$FUNCNAME OK！"
}



# fcitx installer
Fcitx(){
# fonts installer
sudo pacman -Syu && sudo pacman -S ttf-dejavu wqy-zenhei wqy-microhei ttf-monaco  ttf-wps-fonts

sudo pacman -S fcitx-im  fcitx-configtool  fcitx-googlepinyin    

echo '
GTK_IM_MODULE DEFAULT=fcitx
QT_IM_MODULE  DEFAULT=fcitx
XMODIFIERS    DEFAULT=@im=fcitx
INPUT_METHOD  DEFAULT=fcitx
SDL_IM_MODULE DEFAULT=fcitx
' | sudo tee -a /etc/environment

echo '
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
' | sudo tee -a /etc/profile


# need reboot / logout
}

# 更换自定义第三方优化内核
Kernel(){

yay linux-xanmod

echo -e "\033[33m $FUNCNAME \033[0m" 
uname -a
pause "$FUNCNAME OK！"
}



# 修改Grub
Grub(){
# 需要修改grub-cfg开机时间 以及 #自主降频
# 本脚本用来修改引导界面
#取消延时
sudo sed -i 's/GRUB_TIMEOUT=5/GRUB_TIMEOUT=0/g' /etc/default/grub
#取消主题
#sudo sed -i 's/GRUB_THEME/\#GRUB_THEME/g' /etc/default/grub #注释掉
sudo sed -i '/GRUB_BACKGROUND/d' /etc/default/grub #删除
sudo sed -i '/GRUB_THEME/d' /etc/default/grub #删除
#更新grub
sudo update-grub

echo -e "\033[33m $FUNCNAME \033[0m" 
cat /etc/default/grub 
pause "$FUNCNAME OK！"
}

# 安装驱动
Driver(){

# 查看硬件信息 查看系统信息


# 安装intel集成显卡


echo -e "\033[33m $FUNCNAME \033[0m" 
pause "$FUNCNAME OK！"
}





Debtap(){
# 安装Debtap   debtap -q xxx.deb &&   sudo pacman -U xxx.pkg.tar.zst
yay -S --noconfirm debtap
sudo sed -i "s|http://ftp.debian.org/debian/dists|https://mirrors.ustc.edu.cn/debian/dists|g" /usr/bin/debtap
sudo sed -i "s|http://archive.ubuntu.com/ubuntu/dists|https://mirrors.ustc.edu.cn/ubuntu/dists|g" /usr/bin/debtap
sudo debtap -u

}

Build(){
# 安装编译环境    
yay -S --noconfirm etcher


echo -e "\033[33m $FUNCNAME \033[0m" 
pause "$FUNCNAME OK！"
}


# 一键安装 装机必备
One(){
# 一键装机必备
yay -S --noconfirm microsoft-edge-stable-bin xunlei-bin deepin-wine-wechat vscode dbeaver termius smartgit  lx-music-desktop-bin cn.com.10jqka



echo -e "\033[33m $FUNCNAME \033[0m" 
pause "$FUNCNAME OK！"
}
Spark_store(){
# 安装星火商店 本地源里面已经有相同 省略

echo -e "\033[33m $FUNCNAME \033[0m" 
}



Distrobox(){
yay -S --noconfirm distrobox podman

# 修改podman国内源
echo '
unqualified-search-registries = ["docker.io"]

[[registry]]
prefix = "docker.io"
insecure = false
blocked = false
location = "docker.io"

[[registry.mirror]]
location = "dockerproxy.com"
[[registry.mirror]]
location = "hub-mirror.c.163.com"
[[registry.mirror]]
location = "mirror.baidubce.com"
[[registry.mirror]]
location = "ccr.ccs.tencentyun.com"
' | sudo tee -a /etc/containers/registries.conf

#修改存储位置
sudo sed -i 's/graphroot = "/var/lib/containers/storage"/graphroot = "/data/containers/storage"/g' /etc/containers/storage.conf

#把deb解包里面的镜像导入到podman

#wget https://community-packages.deepin.com/beige/pool/commercial/d/deepin-compatibility-mode/deepin-compatibility-mode_0.1.2_amd64.deb

#podman load -i apricot_v20.8-compatible.tar.gz

#再运行distrobox 运行容器就好了

#distrobox create --image localhost/linuxdeepin/apricot:v20.8-compatible --name v20 

#其实没什么太大区别 就是少了启动图标

#distrobox enter v20

}





# 优化开机加速，禁用服务：
Speed(){
#systemd-analyze
#systemd-analyze blame

#sudo systemctl mask ***.service



echo -e "\033[33m $FUNCNAME \033[0m" 
pause "$FUNCNAME OK！"
}

Beautify(){
# 设置桌面壁纸 针对xfce4
#  curl -fsSL http://home/API/api.php/Wallpaper/pc -o /home/admin/My/Pic/Wallpaper/wallpaper.jpg 
# xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitorDP-1/workspace0/last-image --set /home/admin/My/Pic/Wallpaper/wallpaper.jpg
echo -e "\033[33m $FUNCNAME \033[0m" 
pause "$FUNCNAME OK！"
}


Fullupgrade(){
# 全面更新升级命令
sudo pacman -Syyu 
echo -e "\033[33m $FUNCNAME \033[0m" 
pause "$FUNCNAME OK！"
}



Clean(){
#卸载旧内核


echo -e "\033[33m $FUNCNAME \033[0m" 
pause "$FUNCNAME OK！"
}

pause()
{
read -n1 -p "Press any key to continue..." 
}

Help(){
cat << EOF
[list][列表]  
[alias][别名]
[source][软件源]
[kernel][第三方内核]
[grub][启动优化]
[speed][加速]
[upgrade][升级]
[driver][驱动]
[spark-store][星火商店]
[one][安装]
[beautify][美化]
[clean][清理]
[all][全部]
EOF
}
Install_Main(){

	startTime=`date +%s`
	echo $startTime ;
	Alias;
	Source;
	Fcitx;
 	Aur;
#	Kernel
	Grub;
	Speed;

    Fullupgrade;
	Driver;
	Spark_store;
	Build;
	Debtap;
	One;
	Beautify;
	Clean;


}


reset 
echo "
+----------------------------------------------------------------------
| InitShell for Arch
+----------------------------------------------------------------------
| Copyright © 2015-2099 ThinkYoung (https://gitee.com/thinkyoung) All rights reserved.
+----------------------------------------------------------------------
| Enjoy it when installed.
+----------------------------------------------------------------------
"
while [ "$go" != 'y' ] && [ "$go" != 'n' ]
do
	read -p "Do you want to install InitShell for Arch now?(y/n): " go;
done

if [ "$go" == 'n' ];then
	exit;
fi
if [ "$go" == 'y' ];then
echo -e "\033[33m Start！！！ \033[0m"; 
fi


# 软件列表

while [ "$to" != 'exit' ] && [ "$to" != 'quit' ]
do
	Help;
	read -p "选择你要操作的命令(列表:输入list or 1  退出：输入exit or -1 ): " to;


if [  "$to" == 'list'  ] || [  "$to" == 'help'  ];then
	Help;
fi

if [ "$to" == 'alias' ];then
	Alias;
fi

if [ "$to" == 'source' ];then
	Source;
fi
if [ "$to" == 'fcitx' ];then
	Fcitx;
fi
if [ "$to" == 'debtap' ];then
	Debtap;
fi
if [ "$to" == 'Aur' ];then
	Aur;
fi
if [ "$to" == 'build' ];then
	Build;
fi
if [ "$to" == 'kernel' ];then
	Kernel;
fi

if [ "$to" == 'grub' ];then
	Grub;
fi

if [ "$to" == 'speed' ];then
	Speed;
fi

if [ "$to" == 'upgrade' ];then
	Fullupgrade;
fi

if [ "$to" == 'driver' ];then
	Driver;
fi
if [ "$to" == 'spark' ];then
	Spark;
fi
if [ "$to" == 'spark-store' ];then
	Spark_store;
fi



if [ "$to" == 'one' ];then
	One;
fi

if [ "$to" == 'beautify' ];then
	Beautify;
fi

if [ "$to" == 'clean' ];then
	Clean;
fi
if [ "$to" == 'all' ];then
	Install_Main;
fi

if [ "$to" == 'exit' ] || [ "$to" == 'quit' ];then
	exit;
fi



done
#read -s "for auto install,password?" PASSWORD;
#export PASSWORD;
#Install_Main
